package com.aids_malaria.ui.setting;

import android.view.View;

import com.aids_malaria.R;
import com.aids_malaria.app.Constant;
import com.aids_malaria.base.BaseFragment;
import com.aids_malaria.util.AuthUtil;
import com.aids_malaria.util.SpUtil;
import com.aids_malaria.util.ToastUtil;

import butterknife.OnClick;

public class SettingFragment extends BaseFragment {

    private static SettingFragment instance;

    public static SettingFragment getInstance() {
        if(null == instance){
            instance = new SettingFragment();
        }
        return instance;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_setting;
    }

    @OnClick({R.id.tv_setting_work_area, R.id.tv_setting_pad, R.id.tv_setting_account_manage,
            R.id.tv_setting_role_manage, R.id.tv_setting_data_upload, R.id.tv_setting_data_download})
    public void onClick(View vieww){
        boolean isonline = SpUtil.getBoolean(mContext, Constant.IS_WORK_MODEL_ON_LINE,true);
        switch (vieww.getId()){
            case R.id.tv_setting_work_area:
                //工作区域设置
                if (!AuthUtil.isHaveAuthByCode(Constant.SETTING_WORK_AREA)){
                    ToastUtil.showNoPermission();
                    return;
                }
                startActivity(WorkAreaSettingActivity.class);
                break;
            case R.id.tv_setting_pad:
                if (!isonline){
                    ToastUtil.showToast(getString(R.string.This_function_cannot_be_operated_in_offline_mode));
                    return;
                }
                //PAD编号设置
                if (!AuthUtil.isHaveAuthByCode(Constant.SETTING_PAD_SEQ)){
                    ToastUtil.showNoPermission();
                    return;
                }
                startActivity(PadSettingActivity.class);
                break;
            case R.id.tv_setting_account_manage:
                if (!isonline){
                    ToastUtil.showToast(getString(R.string.This_function_cannot_be_operated_in_offline_mode));
                    return;
                }
                //用户管理
                if (!AuthUtil.isHaveAuthByCode(Constant.SETTING_USER_MANAGER)){
                    ToastUtil.showNoPermission();
                    return;
                }
                startActivity(AccountManagerSettingActivity.class);
                break;
            case R.id.tv_setting_role_manage:
                //角色管理
                if (!isonline){
                    ToastUtil.showToast(getString(R.string.This_function_cannot_be_operated_in_offline_mode));
                    return;
                }
                if (!AuthUtil.isHaveAuthByCode(Constant.SETTING_ROLE_MANAGER)){
                    ToastUtil.showNoPermission();
                    return;
                }
                startActivity(RoleManagerSettingActivity.class);
                break;
            case R.id.tv_setting_data_upload:
                if (!isonline){
                    ToastUtil.showToast(getString(R.string.This_function_cannot_be_operated_in_offline_mode));
                    return;
                }
                //数据上传
                startActivity(DataUploadSettingActivity.class);
                break;
            case R.id.tv_setting_data_download:
                if (!isonline){
                    ToastUtil.showToast(getString(R.string.This_function_cannot_be_operated_in_offline_mode));
                    return;
                }
                //数据下载
                startActivity(DataDownloadSettingActivity.class);
                break;
        }
    }

}
